﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_AlterTrain : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string tid =Request.Params["tid"];
            TrainID.Value = tid;

            try
            {
                CmsDataContext db = new CmsDataContext();
                Train train = (from aT in db.Train
                               where aT.ID == tid
                               select aT).First();

                Amend.Text = train.Amended == null ? "" : train.Amend;

                #region 如果项目已经开始，则不允许更改
                if (train.Started.CompareTo(DateTime.Now) <= 0)
                {
                    Save.Visible = false;
                }
                #endregion
            }
            catch
            {
            }
        }
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        CmsDataContext db = new CmsDataContext();

        try
        {
            Train train = (from aT in db.Train
                           where aT.ID == TrainID.Value.Trim()
                           select aT).First();

            train.Amended = DateTime.Now;
            train.Amend = Amend.Text.Trim();

            db.SubmitChanges();

            MessageBox.Message = "项目更改信息已经保存。";
            MessageBox.Location = "./ListTrains.aspx";
        }
        catch (Exception ee)
        {
            MessageBox.Message = "保存项目更改信息时发生错误：" + ee.Message;
        }
    }
}